package com.studentsystem.controller;

import com.studentsystem.common.Result;
import com.studentsystem.dataobject.StudentDO;
import com.studentsystem.service.StudentService;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Student)表控制层
 */
@RestController
@RequestMapping("student")
public class StudentController {

    @Resource
    private StudentService studentService;

    @RequiresRoles("student")
    @GetMapping("/authorization")
    public Result<Object> authorization() {
        return Result.success(null);
    }

    @GetMapping("/getInfo")
    public Result<StudentDO> getStudentInfo(@RequestParam("username") String username) {
        if (StringUtils.isEmpty(username)) {
            return Result.fail("用户名为空", null);
        }

        StudentDO studentDO = studentService.queryByUsername(username);
        if (studentDO == null) {
            return Result.fail("学生信息为空", null);
        }

        return Result.success(studentDO);
    }
}